<template>
   <div class="rightTwo">
        <div class="rightTwo-title">
           进出港航班
        </div>
        <div class="poitime" v-show = showtime>
            更新时间:{{obj.time}}
        </div>
        <div class="flightList">
            <div class="tabs">
                <div class="tabs-left">
                    <div @click="viewFlight" >
                         <span class="lefttitle" id="flightspan">进港航班：</span>
                         <span class="rightnum" id="flightdata"> {{obj.flightIn}}</span>
                    </div>
                    <div>
                         <span class="lefttitle">国际进港航班：</span>
                         <span class="rightnum">{{obj.intlFlightIn}}</span>
                    </div>
                </div>
                <div class="tabs-right">
                    <div>
                        <span class="lefttitle">离港航班：</span>
                        <span class="rightnum">{{obj.flightOut}}</span>
                    </div>
                    <div>
                        <span class="lefttitle">国际出港航班：</span>
                        <span class="rightnum">{{obj.intlFlightOut}}</span>
                    </div> 
                </div>
            </div>
            <div class="flightBody">
            <div class="flightHead">
                <div
                    class="flightHeadList"
                    v-for="(item, index) in thead"
                    :key="index"
                >
                    {{ item }}
                </div>
            </div>
            <div class="myscroll">
                <ul class="flightBody">
                     <li
                        class="flightBodyList"
                        v-for="(item, index) in newtablist"
                        :key="index"
                    >
                        <div>{{ item.flightNo }}</div>
                        <div>{{ item.flightDepcode }}</div>
                        <div>{{ item.flightArrcode }}</div>
                        <div>{{ item.flightArrtimeDate.substr(0,10)}}</div>
                    </li>
                </ul>
            </div>
            </div>
           
        </div>
   </div>
</template>

<script>
import ThemeTitlenew from "../../common/ThemeTitlenew";
import hbName from './chineseName.js'
import countTo from 'vue-count-to';
import axios from "axios";
import one from "./one.js"
import two from "./two.json"
export default {
    data(){
        return{
            tablist:[],
            newtablist:[],
            title:"进出港航班",
            obj:{},
            showtime:false,
            thead:["航班号", "出发地", "目的地", "到达时间"],
            status:0,
            points:[],
        }
    },
    components: {
        ThemeTitlenew,
    },
    watch:{
        obj(oldval,newval){
            this.obj =  oldval
            if(this.obj.time !== "20210813175608"){
                // console.log(this.obj.time)
                var year = this.obj.time.substr(0,4)
                var month = this.obj.time.substr(4,2)
                var day = this.obj.time.substr(6,2)
                var hour = this.obj.time.substr(8,2)
                var minte = this.obj.time.substr(10,2)
                this.timedata = year+"-"+month+"-"+day+" "+hour+":"+minte
                this.showtime = true
                for(let key in this.obj){
                    this.obj.time = this.timedata
                }
            }
        },
        newtablist(newval,oldval){
            this.newtablist = newval
        }
    },
    methods:{
        showDynamicline(){
              const geoCoordMap = {
        '上海': [121.4648,31.2891],
        '东莞': [113.8953,22.901],
        '东营': [118.7073,37.5513],
        '中山': [113.4229,22.478],
        '临汾': [111.4783,36.1615],
        '临沂': [118.3118,35.2936],
        '丹东': [124.541,40.4242],
        '丽水': [119.5642,28.1854],
        '乌鲁木齐': [87.9236,43.5883],
        '佛山': [112.8955,23.1097],
        '保定': [115.0488,39.0948],
        '兰州': [103.5901,36.3043],
        '包头': [110.3467,41.4899],
        '北京': [116.4551,40.2539],
        '北海': [109.314,21.6211],
        '南京': [118.8062,31.9208],
        '南宁': [108.479,23.1152],
        '南昌': [116.0046,28.6633],
        '南通': [121.1023,32.1625],
        '厦门': [118.1689,24.6478],
        '台州': [121.1353,28.6688],
        '合肥': [117.29,32.0581],
        '呼和浩特': [111.4124,40.4901],
        '咸阳': [108.4131,34.8706],
        '哈尔滨': [127.9688,45.368],
        '唐山': [118.4766,39.6826],
        '嘉兴': [120.9155,30.6354],
        '大同': [113.7854,39.8035],
        '大连': [122.2229,39.4409],
        '天津': [117.4219,39.4189],
        '太原': [112.3352,37.9413],
        '威海': [121.9482,37.1393],
        '宁波': [121.5967,29.6466],
        '宝鸡': [107.1826,34.3433],
        '宿迁': [118.5535,33.7775],
        '常州': [119.4543,31.5582],
        '广州': [113.5107,23.2196],
        '廊坊': [116.521,39.0509],
        '延安': [109.1052,36.4252],
        '张家口': [115.1477,40.8527],
        '徐州': [117.5208,34.3268],
        '德州': [116.6858,37.2107],
        '惠州': [114.6204,23.1647],
        '成都': [103.9526,30.7617],
        '扬州': [119.4653,32.8162],
        '承德': [117.5757,41.4075],
        '拉萨': [91.1865,30.1465],
        '无锡': [120.3442,31.5527],
        '日照': [119.2786,35.5023],
        '昆明': [102.9199,25.4663],
        '杭州': [119.5313,29.8773],
        '枣庄': [117.323,34.8926],
        '柳州': [109.3799,24.9774],
        '株洲': [113.5327,27.0319],
        '武汉': [114.3896,30.6628],
        '汕头': [117.1692,23.3405],
        '江门': [112.6318,22.1484],
        '沈阳': [123.1238,42.1216],
        '沧州': [116.8286,38.2104],
        '河源': [114.917,23.9722],
        '泉州': [118.3228,25.1147],
        '泰安': [117.0264,36.0516],
        '泰州': [120.0586,32.5525],
        '济南': [117.1582,36.8701],
        '济宁': [116.8286,35.3375],
        '海口': [110.3893,19.8516],
        '淄博': [118.0371,36.6064],
        '淮安': [118.927,33.4039],
        '深圳': [114.5435,22.5439],
        '清远': [112.9175,24.3292],
        '温州': [120.498,27.8119],
        '渭南': [109.7864,35.0299],
        '湖州': [119.8608,30.7782],
        '湘潭': [112.5439,27.7075],
        '滨州': [117.8174,37.4963],
        '潍坊': [119.0918,36.524],
        '烟台': [120.7397,37.5128],
        '玉溪': [101.9312,23.8898],
        '珠海': [113.7305,22.1155],
        '盐城': [120.2234,33.5577],
        '盘锦': [121.9482,41.0449],
        '石家庄': [114.4995,38.1006],
        '福州': [119.4543,25.9222],
        '秦皇岛': [119.2126,40.0232],
        '绍兴': [120.564,29.7565],
        '聊城': [115.9167,36.4032],
        '肇庆': [112.1265,23.5822],
        '舟山': [122.2559,30.2234],
        '苏州': [120.6519,31.3989],
        '莱芜': [117.6526,36.2714],
        '菏泽': [115.6201,35.2057],
        '营口': [122.4316,40.4297],
        '葫芦岛': [120.1575,40.578],
        '衡水': [115.8838,37.7161],
        '衢州': [118.6853,28.8666],
        '西宁': [101.4038,36.8207],
        '西安': [109.1162,34.2004],
        '贵阳': [106.6992,26.7682],
        '连云港': [119.1248,34.552],
        '邢台': [114.8071,37.2821],
        '邯郸': [114.4775,36.535],
        '郑州': [113.4668,34.6234],
        '鄂尔多斯': [108.9734,39.2487],
        '重庆': [107.7539,30.1904],
        '金华': [120.0037,29.1028],
        '铜川': [109.0393,35.1947],
        '银川': [106.3586,38.1775],
        '镇江': [119.4763,31.9702],
        '长春': [125.8154,44.2584],
        '长沙': [113.0823,28.2568],
        '长治': [112.8625,36.4746],
        '阳泉': [113.4778,38.0951],
        '青岛': [120.4651,36.3373],
        '韶关': [113.7964,24.7028]
              };
              const XAData = [
                  [{name:'海口'}, {name:'北京',value:100}],
                  [{name:'海口'}, {name:'上海',value:100}],
                  [{name:'海口'}, {name:'广州',value:100}],
                  [{name:'海口'}, {name:'西宁',value:100}],
                  [{name:'海口'}, {name:'银川',value:100}],
              ];
          
              const XNData = [
                  [{name:'西宁'}, {name:'北京',value:100}],
                  [{name:'西宁'}, {name:'上海',value:100}],
                  [{name:'西宁'}, {name:'广州',value:100}],
                  [{name:'西宁'}, {name:'西安',value:100}],
                  [{name:'西宁'}, {name:'银川',value:100}]
              ];
          
              const YCData = [
                  [{name:'银川'}, {name:'北京',value:100}],
                  [{name:'银川'}, {name:'广州',value:100}],
                  [{name:'银川'}, {name:'上海',value:100}],
                  [{name:'银川'}, {name:'西安',value:100}],
                  [{name:'银川'}, {name:'西宁',value:100}],
              ];
              const planePath = 'path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z';
                 const convertData = function (data) {
                  const res = [];
                  for (let i = 0; i < data.length; i++) {

                      const dataItem = data[i];

                      const fromCoord = geoCoordMap[dataItem[0].name];
                      const toCoord = geoCoordMap[dataItem[1].name];
                      if (fromCoord && toCoord) {
                          res.push({
                              fromName: dataItem[0].name,
                              toName: dataItem[1].name,
                              coords: [fromCoord, toCoord],
                              value: dataItem[1].value
                          });
                      }
                  }
                  return res;
                   };
            const color = ['#a6c84c', '#ffa022', '#46bee9'];//航线的颜色
               const series = [];
        [['海口', XAData], ['西宁', XNData], ['银川', YCData]].forEach(function (item, i) {
        series.push(
            {
                name: item[0] + ' Top3',
                type: 'lines',
                coordinateSystem: 'GLMap',
                zlevel: 1,
                effect: {
                    show: true,
                    period: 6,
                    trailLength: 0.7,
                    color: 'red',   //arrow箭头的颜色
                    symbolSize: 3
                },
                lineStyle: {
                    normal: {
                        color: color[i],
                        width: 0,
                        curveness: 0.2
                    }
                },
                data: convertData(item[1])
            },
            {
                name: item[0] + ' Top3',
                type: 'lines',
                coordinateSystem: 'GLMap',
                zlevel: 2,
                symbol: ['none', 'arrow'],
                symbolSize: 10,
                effect: {
                    show: true,
                    period: 6,
                    trailLength: 0,
                    symbol: planePath,
                    symbolSize: 15
                },
                lineStyle: {
                    normal: {
                        color: color[i],
                        width: 1,
                        opacity: 0.6,
                        curveness: 0.2
                    }
                },
                data: convertData(item[1])
            },
            {
                name: item[0] + ' Top3',
                type: 'effectScatter',
                coordinateSystem: 'GLMap',
                zlevel: 2,
                rippleEffect: {
                    brushType: 'stroke'
                },
                label: {
                    normal: {
                        show: true,
                        position: 'right',
                        formatter: '{b}'
                    }
                },
                symbolSize: function (val) {
                    return val[2] / 8;
                },
                itemStyle: {
                    normal: {
                        color: color[i],
                    },
                    emphasis: {
                        areaColor: '#2B91B7'
                    }
                },
                data: item[1].map(function (dataItem) {
                    return {
                        name: dataItem[1].name,
                        value: geoCoordMap[dataItem[1].name].concat([dataItem[1].value])
                    };
                })
            });
    });
       this.option = {
        animation: !1,
        GLMap: {},
        series: series
       };
        fmh.combineEcharts(this.option);
        },
        initSensotWebsocket(){
			let websocket = null
            const wsuri = window.hangbanUrl;
			if ('WebSocket') {
				websocket = new WebSocket(wsuri)
                // websocket = new WebSocket(window.huoqingUrl)
			} else {
				alert('当前浏览器 Not support websocket')
			}
			//连接发生错误的回调方法
			websocket.onerror = function() {
				console.log('WebSocket连接发生错误')
			}
			//连接成功建立的回调方法
			websocket.onopen = function() {
				console.log('WebSocket连接成功')
			}
			//接收到消息的回调方法
            let that = this
			websocket.onmessage = ((event)=> {
                // console.log(JSON.parse(event.data))
                let res = JSON.parse(event.data)
                if(res.type == "航班统计信息"){
                    // console.log(123)
                     that.obj = JSON.parse(res.data)
                     
                }
                if(res.type == "航班详细信息"){
                    for(var i = 0;i<res.data.length;i++){
                        that.newtablist.push(JSON.parse(res.data[i].payload))
                    }
                for(var i =0;i<this.newtablist.length;i++){
                 for(var j =0;j<this.chineseName.length;j++){
                    if(this.newtablist[i].flightDepcode ==  this.chineseName[j].三字码){
                        this.newtablist[i].flightDepcode = this.chineseName[j].所在城市
                    }
                    if(this.newtablist[i].flightArrcode ==  this.chineseName[j].三字码){
                        this.newtablist[i].flightArrcode = this.chineseName[j].所在城市
                    }
                }
            }
                }
			})
			//连接关闭的回调方法
			// websocket.onclose = function() {
			// 	console.log('WebSocket连接关闭')
			// }
			//监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
			window.onbeforeunload = function() {
				closeWebSocket()
			}
			//关闭WebSocket连接
			function closeWebSocket() {
				websocket.close()
			}
        },
        aircraftRoute(){
            // for(var i =0;i<this.newtablist.length;i++){
            //     let obj ={}
            //     obj.lat = this.newtablist[i].lat
            //     obj.lon = this.newtablist[i].lon
            //     this.points.push(obj)
            // }
            // 海口
             const points=[{lon: 110.4588889, lat: 19.93472222}];
             const center=[
                //  {"lon": 115.028495718,"lat": 30.200814617};
                 {"lon": 110.795000473,"lat": 32.638540762},
                 {"lon": 111.267729446,"lat": 30.698151246},
                 {"lon": 112.126643144,"lat": 32.058588576},
                 {"lon": 114.885884938,"lat": 30.395401912},
                 {"lon": 112.190419415,"lat": 31.043949588},
                 {"lon": 113.903569642,"lat": 30.932054050},
                 {"lon": 112.226648859,"lat": 30.367904255},
                 {"lon": 114.861716770,"lat": 30.468634833},
                 {"lon": 114.317846048,"lat": 29.848946148},
                 {"lon": 113.371985426,"lat": 31.704988330},
                 {"lon": 109.468884533,"lat": 30.289012191},
                 {"lon": 113.414585069,"lat": 30.368350431},
                 {"lon": 112.892742589,"lat": 30.409306203},
                 {"lon": 113.160853710,"lat": 30.667483468},
                 {"lon": 110.670643354,"lat":31.748540780}]
                for(var i =0;i<center.length;i++){
                      const data={
                    image:"./libs/ysCesium/images/飞机.png", //如果有其他需求 就直接修改ysc内部代码吧 这边就简单写几个参数
                    center:center[i],
                    points:points,
                    height:50000,//抛物线的最高点
                    multiplier:100,//动画的运行时间加快倍数//速度
                    lineColor:[109, 243, 255,200]//线的颜色 最后一个255就相当于1
            };
            // points.forEach((ele)=>{
            //    fmh.addCircleScan({
            //       lon:parseFloat(ele.lon),//经度
            //       lat:parseFloat(ele.lat), //纬度
            //       scanColor:Cesium.Color.fromCssColorString('#67ADDF'),
            //       r:22000,//扫描半径
            //       interval:2000//时间间隔
            //    });
            // })
            this.dsArr=fmh.addFlyLinesByCZML(data); // shouldAnimate : true,//允许动画 //这个得必须有！！
                }
           
            layerManager.fly(
                 113.78257977527866,30.981032380450582,8054611,0.02211233042936378,-1.5517014134408793,0
            );

        },
        viewFlight(){
            if(this.status == 0){
                layerManager.fly(
                    113.78257977527866,30.981032380450582,8054611,0.02211233042936378,-1.5517014134408793,0
                );
                var flight = document.getElementById("flightspan")
                var fligtdata = document.getElementById("flightdata")
                flight.style.color="#00e5fd"
                fligtdata.style.color="#00e5fd"
                this.status = 1
                // this.showDynamicline()
                this.aircraftRoute()
            }else if(this.status == 1){
                var flight = document.getElementById("flightspan")
                var fligtdata = document.getElementById("flightdata")
                flight.style.color="#ffffff"
                fligtdata.style.color="#ffffff"
                this.status = 0
                 layerManager.removeAll();
                layerManager.fly(
                    109.81718500012782,
                    19.345261718452747,
                    474882,
                    6.237318703147128,
                    -1.5704875459600833,
                    0
                );
            }
        }
    },
    created(){
    },
    mounted(){
        this.initSensotWebsocket()
         $(function () {
            $(".myscroll").myScroll({
                speed: 40, //数值越大，速度越慢
                rowHeight: 26, //li的高度
            });
        });
        this.chineseName = hbName
        this.newtablist = one
        for(var i =0;i<this.newtablist.length;i++){
            for(var j =0;j<this.chineseName.length;j++){
                if(this.newtablist[i].flightDepcode ==  this.chineseName[j].三字码){
                    this.newtablist[i].flightDepcode = this.chineseName[j].所在城市
                } 
                if(this.newtablist[i].flightArrcode ==  this.chineseName[j].三字码){
                    this.newtablist[i].flightArrcode = this.chineseName[j].所在城市
                }
            }
        }
        // if(one.type == "航班详细信息"){
        //     for(var i =0;i<this.newtablist.length;i++){
        //         // this.newtablist[i].flightArrtimeDate =  this.timedata
        //         for(var j =0;j<this.chineseName.length;j++){
        //             if(this.newtablist[i].flightDepcode ==  this.chineseName[j].三字码){
        //                 this.newtablist[i].flightDepcode = this.chineseName[j].所在城市
        //                 this.newtablist[i].lon = this.chineseName[j].lon
        //                 this.newtablist[i].lat = this.chineseName[j].lat
        //                 // this.newtablist[i].flightArrtimeDate = this.newtablist[i].flightArrtimeDate.substr(0,10)
        //             }
        //             if(this.newtablist[i].flightArrcode ==  this.chineseName[j].三字码){
        //                 this.newtablist[i].flightArrcode = this.chineseName[j].所在城市
        //             }
        //         }
        //     }
        // }
        if(two.type == "航班统计信息"){
            this.obj = JSON.parse(two.data)
        }
    },
    beforeDestroy(){
        this.option= null
        fmh.combineEcharts(this.option);
    }
}

</script>

<style lang="stylus" scoped>
@media (max-width: 2880px) {
    .rightTwo {
          .rightTwo-title{
               height: vh(24);
            width: vw1(364);
            padding-left:vw1(12);
		line-height: vh(24);
		border-left: 2px solid #00e5fd;
		font-family: 'FZTYSJW';
		font-size: 18px;
		font-weight: 600;
		text-align: left;
		color: #ffffff;
		text-shadow: 0px 4px 4px 0px #000000;
		background-clip: text;
		-webkit-text-fill-color: transparent;
		background-image: -webkit-linear-gradient(bottom, #00eaff, #ffffff);
        // background:Pink;
        margin-bottom:vh(10);
        }
        .poitime{
            width:vw(220);
            height:vh(35);
            line-height :vh(35)
            // background:pink;
            position:absolute;
            top:vh(505);
            left:vw(160);
        }
        .flightList {
            margin-top: vh(10);
            margin-bottom: vh(20);
            height: vh(430);
            // background:pink;
            overflow: hidden;
            .tabs {
                display: flex;
                // justify-content: space-around;
                margin-bottom: vh(16);
                width: 100%;
                // cursor: pointer;
                .tabs-left{
                    width:50%;
                    height:vh(80);
                    // background:blue;
                    float:left;
                    div{
                        width:100%;
                        height:vh(40);
                        line-height:vh(30);
                        text-align:center;
                        cursor:not-allowed;
                    }
                    div:nth-child(1){
                         cursor:pointer;
                    }
                }
                .tabs-right{
                    width:50%;
                    height:vh(80);
                    // background:pink;
                    float:left;
                     div{
                        width:100%;
                        height:vh(40);
                        line-height:vh(30);
                        text-align:center;
                        cursor:not-allowed;
                    }
                }
                .active {
                    background: #03587e;
                    border: 1px solid #1398cf;
                }
            }
            .flightHead {
                width: 100%;
                height: vh(40);
                background:rgba(3, 32, 64.0.2);
                box-shadow: 0px 0px 5px #01c7ff inset
                line-height: vh(40);
                display: flex;
                justify-content: space-between;
                font-size: vw(15);
                // background:rgb(2, 45, 64,0.6)
                //  border-top:1.1px solid #ffffff;
                //  border-bottom:0.5px solid #ffffff;
                // background:pink;

                .flightHeadList {
                    flex-shrink: 0;
                    flex: 3;
                    text-align: center;
                    // color: #37DCFF;
                    color:#ffffff;
                    font-weight: 700;
                    // border-top:2px solid #ffffff;
                }

                div:nth-child(1) {
                    flex-shrink: 0;
                    flex: 2;
                    // border-bottom: 1px solid #213034;
                    text-align: center;
                    font-weight: 400;
                }
            }
        }

        .myscroll {
            height: vh(280);
            width:100%;
            // background: url('/data/images/hngk/自然地理.png') no-repeat;
            // background:100% 100%;
            background:rgba(3, 32, 64.0.2);
            box-shadow: 0px 0px 5px #01c7ff inset
            overflow: hidden;
            .flightBody {
                .flightBodyList {
                    display: flex;
                    justify-content: space-between;
                    width: vw(363);
                    height: vh(32);
                    line-height: vh(32);
                    font-size: vw(13);
                    div {
                        flex-shrink: 0;
                        flex: 3;
                        // border-top: 1px solid #213034;
                        text-align: center;
                        font-weight: 400;
                    }

                    div:nth-child(1) {
                        flex-shrink: 0;
                        flex: 2;
                        // border-top: 1px solid #213034;
                        text-align: center;
                        font-weight: 400;
                    }
                }
            }
        }
    }
}
</style>

<style lang="stylus" scoped>
@media (min-width: 3000px) {
    .rightTwo {
        position: absolute;
        top: vh(410);
        right:vw1(25);
        .flightList {
            // margin-top: vh(2);
            margin-bottom: vh(20);
            height: vh(350);
            overflow: hidden;
            background :pink;
            .tabs {
                display: flex;
                justify-content: space-around;
                margin-bottom: vh(26);
                width: vw1(414);
                margin-top: vh(20);
                cursor: pointer;
                background :pink;
                .tab {
                    flex: 1;
                    background: #023850;
                    // border: 1px solid #07384D;
                    display: flex;
                    // justify-content: space-around;
                    line-height: vh(40);
                    padding-left: vw1(0);
                    padding-right: vw1(10);
                    font-size: vw1(18);
                }
                .active {
                    background: #03587e;
                    border: 1px solid #1398cf;
                }
            }

            .flightHead {
                width: vw1(414);
                height: vh(40);
                line-height: vh(30);
                display: flex;
                justify-content: space-between;
                font-size: vw1(15);
                .flightHeadList {
                    flex-shrink: 0;
                    flex: 3;
                    text-align: center;
                    color: #37DCFF;
                    font-weight: 700;
                   
                }

                div:nth-child(1) {
                    flex-shrink: 0;
                    flex: 2;
                    border-bottom: 1px solid #213034;
                    text-align: center;
                    font-weight: 400;
                }
            }
        }

        .myscroll {
            height: vh(320);
            overflow: hidden;
            background:pink;
            .flightBody {
                .flightBodyList {
                    display: flex;
                    justify-content: space-between;
                    width: vw1(414);
                    height: vh(40);
                    line-height: vh(40);
                    font-size: vw1(16);

                    div {
                        flex-shrink: 0;
                        flex: 3;
                        border-top: 1px solid #213034;
                        text-align: center;
                        font-weight: 400;
                    }

                    div:nth-child(1) {
                        flex-shrink: 0;
                        flex: 2;
                        border-top: 1px solid #213034;
                        text-align: center;
                        font-weight: 400;
                    }
                }
            }
        }
    }
}
</style>